<script setup lang="ts">
import {ConformanceHint, TaskResponse, TaskRecordResponse} from "@/views/platform/platformType";
import {onMounted, ref, Ref} from "vue";
import {conformanceHint} from "@/api/platform";
import {useRouter} from "vue-router";

const router = useRouter();
const hints:Ref<ConformanceHint[]> = ref([]);

function goToListPage(){
  router.push('/compliance')
}

onMounted(async () => {
  const response = await conformanceHint();
  const responseData: TaskResponse = response.data;
  hints.value = responseData.records.map((item: TaskRecordResponse) => {
    return {
      id: item.taskId,
      dateTime: item.startHandleTime,
      title: item.taskName,
      organization: item.createOrgName
    }
  });
});
</script>

<template>
  <div class="component-wrap">
    <div class="component-title">
      <div class="title-text">合规提示</div>
    </div>
    <div class="list">
      <div v-for="(hint,index) in hints" :key="hint.id" class="list-item">
        <div class="item-title">{{ hint.title }}</div>
        <div class="bottom">
          <div class="organization">单位{{ hint.organization }}</div>
          <div class="date-time">{{ hint.dateTime }}</div>
        </div>
        <div v-if="index < hints.length - 1" class="divider"></div>
      </div>
      <van-button type="primary" color="#f1f3fe" block @click="goToListPage">
        查看更多
        <van-icon name="play" />
      </van-button>
    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: "conformanceHint"
}
</script>

<style scoped lang="scss">
.component-title{
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  .title-text{
    font-size: 1.2rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    &:before{
      content: '';
      display: block;
      width: 0.3rem;
      height: 1.2rem;
      background-color: #4b6fd6;
      margin-right: 0.3rem;
    }
  }
}
.list{
  background-color: #FFFFFF;
  padding: 0.5rem;
  border: 1px solid #f2f2f2;
  border-radius: 0.2rem;
}
.list-item{
  margin-bottom: 1rem;
}
.item-title{
  font-weight: bold;
  margin-bottom: 0.5rem;
  line-height: 1.3rem;
}
.bottom{
  display: flex;
  align-items: center;
  color: #727272;
  font-size: 0.8rem;
}
.organization{
  margin-right: 0.75rem;
  display: flex;
  align-items: center;
  &:after{
    content: '';
    display: inline-block;
    width: 2px;
    height: 2px;
    background-color: #8b8b8b;
    border: 1px solid #8b8b8b;
    border-radius: 50%;
    margin-left: 0.75rem;
  }
}
.divider{
  width: 100%;
  height: 1px;
  background-color: #f2f2f2;
  margin-top: 1rem;
}
:deep(.van-button__text){
  color: #4b6ed6;
}
</style>